import json
from datetime import datetime

# 示例数据
data = {
    "rc": 0,
    "rt": 6,
    "svr": 182482412,
    "lt": 1,
    "full": 1,
    "dlmkts": "",
    "data": {
        "total": 114,
        "diff": [
            {
                "f1": 3,
                "f2": 0.23,
                "f3": 10.05,
                "f4": 0.021,
                "f5": 50250,
                "f6": 1150848.0,
                "f7": 4.78,
                "f8": 2.73,
                "f9": 1324.73,
                "f10": 2.72,
                "f11": 0.0,
                "f12": "900957",
                "f13": 1,
                "f14": "凌云Ｂ股",
                "f15": 0.23,
                "f16": 0.22,
                "f17": 0.23,
                "f18": 0.209,
                "f20": 80270000,
                "f21": 42320000,
                "f22": 0.0,
                "f115": 18.11,
                "f128": "-",
                "f140": "-",
                "f141": "-",
                "f136": "-",
                "f152": 2
            }
            # ...（省略其他数据，以节省空间）
        ]
    }
}

# 设置当前日期
current_date = datetime.now().strftime('%Y%m%d')

# 遍历 diff 列表，为每条数据添加 dt 字段
diff_data = data.get('data', {}).get('diff', [])
# for item in data['data']['diff']:
for item in diff_data:
    item['dt'] = current_date

# 在最外层添加 trandt 字段
data['trandt'] = current_date

# 将数据转换为 JSON 格式
json_data = json.dumps(data, ensure_ascii=False, indent=4)

print(json_data)
